﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GolSig.Library;

namespace GolSig.Console
{
   
        class Program
        {
            private const int rows = 10;
            private const int cols = 10;
            static void Main(string[] args)
            {
                var gameOfLife = new Game(new BoardSize(rows, cols));
                gameOfLife.Initialize(new CellInfo[] { new CellInfo(new Position ( 5, 5 ), true), new CellInfo(new Position( 5,  6 ), true), new CellInfo(new Position ( 4,  6 ), true), new CellInfo(new Position ( 6,  7 ), true),new CellInfo( new Position (7,  8 ), true) });


                DumpGrid(gameOfLife);
                System.Console.WriteLine("");
                System.Console.WriteLine("press c");
                ConsoleKeyInfo key = System.Console.ReadKey(true);

                while (key.KeyChar == 'c')
                {
                    gameOfLife.Next();
                    DumpGrid(gameOfLife);
                    System.Console.WriteLine("press c");
                    key = System.Console.ReadKey(true);
                }


            }

            private static void DumpGrid(Game game)
            {
               

                foreach (var item in game.Cells())
                {
                    if (item.Alive)
                    {
                        if (item.Position.Column == cols - 1)
                        {
                            System.Console.WriteLine("X");
                        }
                        else
                        {
                            System.Console.Write("X");
                        }
                    }
                    else
                    {
                        if (item.Position.Column == cols - 1)
                        {
                            System.Console.WriteLine(" ");
                        }
                        else
                        {
                            System.Console.Write(" ");
                        }
                    }
                }

                System.Console.WriteLine();
            }
        }
    
}
